import time

from Base.Base import Base
from selenium.webdriver.common.by import By
from selenium import webdriver


class Page3(Base):

    #点击登录文本
    login_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def login(self):
        self.click(self.login_loc)

    #断言
    dy1_loc=(By.CLASS_NAME,'reg-new')
    def dy1(self):
        return self.text(self.dy1_loc)

    #输入用户名
    user_loc=(By.NAME,'username')
    def username(self):
        self.send_keys(self.user_loc,'13811033962')

    #s输入密码
    password_loc=(By.NAME,'password')
    def password(self):
        self.send_keys(self.password_loc,'123456')

    #点击登录按钮
    an_loc=(By.CLASS_NAME,'finish-btn')
    def an(self):
        self.click(self.an_loc)

    #点击首页
    sy_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def sy(self):
        self.click(self.sy_loc)

    #点击搜索框输入
    sousuo_loc=(By.CSS_SELECTOR,'#searchForm > div.header-search > input')
    def sousuo(self):
        self.send_keys(self.sousuo_loc,'音乐耳机')

    #点击搜索按钮
    san_loc=(By.CLASS_NAME,'search-input-btn')
    def san(self):
        self.click(self.san_loc)

    # 断言
    dy2_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/em/a')
    def dy2(self):
        return self.text(self.dy2_loc)

    #点击商品图片
    img_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img')
    def img(self):
        self.click(self.img_loc)

    # 断言三
    dy3_loc = (By.XPATH, '/html/body/div[5]/div/div[2]/form/div/div[1]/span')
    def dy3(self):
        return self.text(self.dy3_loc)

    #点击购买
    buy_loc=(By.ID,'buy-cart')
    def buy(self):
        self.click(self.buy_loc)

    #点击下一步
    next_loc=(By.ID,'order-button')
    def next(self):
        self.click(self.next_loc)


    def luoji_a3mall_buy(self):
        self.open_url('http://10.59.9.12:7001/')
        time.sleep(5)
        self.login()
        print("断言1：", self.dy1())
        self.username()
        self.password()
        time.sleep(15)
        self.an()
        self.sy()
        self.sousuo()
        self.san()
        print("断言2：", self.dy2())
        self.img()
        self.buy()
        self.next()
        time.sleep(4)